﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Arbetsfornedringen.Pages;
using DAL;

namespace Arbetsfornedringen
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            GridAds.DataSource = DAL.AdDB.GetWorkAds();
            GridAds.DataBind();
        }

        protected void SaveAd(WorkAds ad)
        {
            Account acc = Session["Account"] as Account;
            if (acc != null)
            {
                acc.AppliedJob.Add(ad);
                Model.GetContext().SaveChanges();
            }
            else
                Response.Redirect(@"~\Pages\Login.aspx");

        }
        protected void GridAds_RowCommand1(object sender, GridViewCommandEventArgs e)
        {
            bool verify = e.CommandName == "ApplyJob";
            if (verify)
            {
                int workID = int.Parse(GridAds.Rows[int.Parse(e.CommandArgument.ToString())].Cells[0].Text);
                WorkAds ad = Model.GetContext().WorkAdsSets.FirstOrDefault(a => a.WorkId == workID);
                SaveAd(ad);
            }


        }



    }
}